package io.renren.modules.app.controller;


import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.UserData;
import io.renren.modules.app.service.UserDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 用户数据表
 *
 * @author chenjiacheng
 * @email 
 * @date 2019-02-11 19:04:20
 */
@RestController
@RequestMapping("app/userdata")
public class UserDataController {
    @Autowired
    private UserDataService userDataService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("app:userdata:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userDataService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    @RequiresPermissions("app:userdata:info")
    public R info(@PathVariable("userId") Integer userId){
			UserData userData = userDataService.selectById(userId);

        return R.ok().put("userData", userData);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("app:userdata:save")
    public R save(@RequestBody UserData userData){
			userDataService.insert(userData);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("app:userdata:update")
    public R update(@RequestBody UserData userData){
			userDataService.updateById(userData);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("app:userdata:delete")
    public R delete(@RequestBody Integer[] userIds){
			userDataService.deleteBatchIds(Arrays.asList(userIds));

        return R.ok();
    }

}
